import { Content } from "ant-design-vue/lib/layout/layout";
import { postLoginAPI,postRegisterAPI } from "../../api/userinfo"
import { loginParams,registerParams } from "../../types/parmas";
const user = {
  state: {
    token:"", //用户认证token
    userInfo: {
    }, //用户登录基本信息
  },

  mutations: {
    //保存用户基本信息
    SET_USERINFO(state: any, value: any) {
      state.token = value.token;
      state.userInfo=value.user 
    },
  },

  actions: {
    //登录
    async SET_LOGIN(content:any,Login:loginParams){
      await postLoginAPI(Login).then((res)=>{
        content.commit("SET_USERINFO",res.data)    
      })
    },
    //注册
     SET_REGISTER(content:any,Register:registerParams){
      return new Promise(async resolve=>{
            await postRegisterAPI(Register).then((res)=>{
            content.commit("SET_USERINFO",res.data)
            resolve(resolve)
      })
      })
    }
  },
};

export default user;
